package cn.duhengkui.national.poi.utils;

import java.io.IOException;
import java.io.InputStream;

import cn.duhengkui.national.poi.word.CustomXWPFDocument;  
   
   
public class WordUtil {    
   
    /** 
     * 根据图片类型，取得对应的图片类型代码  
     * @param picType  
     * @return int  
     */   
    public static int getPictureType(String picType){    
        int res = CustomXWPFDocument.PICTURE_TYPE_PICT;    
        if(picType != null){   
            if(picType.equalsIgnoreCase("png")){   
                res = CustomXWPFDocument.PICTURE_TYPE_PNG;    
            }else if(picType.equalsIgnoreCase("dib")){   
                res = CustomXWPFDocument.PICTURE_TYPE_DIB;    
            }else if(picType.equalsIgnoreCase("emf")){   
                res = CustomXWPFDocument.PICTURE_TYPE_EMF;    
            }else if(picType.equalsIgnoreCase("jpg") || picType.equalsIgnoreCase("jpeg")){   
                res = CustomXWPFDocument.PICTURE_TYPE_JPEG;    
            }else if(picType.equalsIgnoreCase("wmf")){   
                res = CustomXWPFDocument.PICTURE_TYPE_WMF;    
            }else if(picType.equalsIgnoreCase("gif")){   
                res = CustomXWPFDocument.PICTURE_TYPE_JPEG;    
            }   
        }   
        return res;    
    }   
    /** 
     * 将输入流中的数据写入字节数组  
     * @param in  
     * @return  
     */   
    public static byte[] inputStream2ByteArray(InputStream in,boolean isClose){    
        byte[] byteArray = null;   
        try{    
            int  total = in.available();    
            byteArray = new  byte[total];   
            in.read(byteArray);   
        }catch(IOException e) {    
            e.printStackTrace();   
        }finally{   
            if(isClose){   
                try{    
                    in.close();   
                }catch(Exception e2) {    
                    System.out.println("关闭流失败");   
                }   
            }   
        }   
        return byteArray;    
    }   
}  